package ru.nsu.effel.actions;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import ru.nsu.effel.persistence.Account;
import ru.nsu.effel.persistence.AccountManager;

public class AccountActionBean implements ActionBean {
	private ActionBeanContext context;
	private Account account;
	private long accountId;
	private String fio;
	
	public ActionBeanContext getContext() {
		return context;
	}
		
	public void setContext(ActionBeanContext context) {
		this.context = context;
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public long getAccountId() {
		return accountId;
	}

	public void setAccountId(long accountId) {
		this.accountId = accountId;
	}

	public String getFio() throws IOException {
		HttpSession session = getContext().getRequest().getSession(false);
		Integer accountId = (Integer) session.getAttribute("accountId");
		Account account = AccountManager.getInstance().getAccountById(accountId);
		if (null == account) {
			throw new IOException("Unknown account ID");
		}
		fio = account.getLastName()+" "+account.getFirstName();
		return fio;
	}
}
